﻿using MyTodo.Services.Interfaces;
using MyTodo.Shared.Dtos;
using MyTodo.Shared.Parameters;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyTodo.ViewModels;

public class MemoViewModel : BindableBase
{
    private readonly IMemoService _service;
    private bool _isRightDrawerOpen;

    public MemoViewModel(IMemoService service)
    {
        _service = service;
        AddCommand = new DelegateCommand(AddMemo);
        CreateTestData();
    }

    public ObservableCollection<MemoDto> MemoDtos { set; get; } = new ObservableCollection<MemoDto>();

    public DelegateCommand AddCommand { get; private set; }

    public bool IsRightDrawerOpen
    {
        get => _isRightDrawerOpen;
        set
        {
            _isRightDrawerOpen = value; RaisePropertyChanged();
        }
    }

    private void AddMemo()
    {
        IsRightDrawerOpen = true;
    }

    private async void CreateTestData()
    {
        var memoResult = await _service.GetAllAsync(new QueryParameter() { PageIndex = 0, PageSize = 100 });
        if (memoResult.Status && memoResult.Result != null)
        {
            MemoDtos.Clear();
            MemoDtos.AddRange(memoResult.Result.Items);
        }
    }
}
